﻿using System.Linq;
using System.Speech.Synthesis;
using TruckScale.Models;

namespace TruckScale.Helpers
{
  public static class TTSHelper
  {
    public static void TTS(string text)
    {
      try
      {
        var speechSpeed = int.Parse(Global._weighConfig["SpeechSpeed"]);
        var speaker = new SpeechSynthesizer
        {
          Rate = speechSpeed,
          Volume = 100
        };

        string str = text;

        speaker.SpeakAsync(str);
      }
      catch { }
    }

    public static void TTS(WeighRecordModel wrm, string text)
    {
      try
      {
        var speechSpeed = int.Parse(Global._weighConfig["SpeechSpeed"]);
        var speaker = new SpeechSynthesizer
        {
          Rate = speechSpeed,
          Volume = 100
        };

        string ch = string.Join(" ", wrm.Ch.Select(c => c.ToString()));

        string str = text.Replace("%ch%", ch)
                        .Replace("%mz%", wrm.Mz)
                        .Replace("%pz%", wrm.Pz)
                        .Replace("%jz%", wrm.Jz)
                        .Replace("%by1%", wrm.By1)
                        .Replace("%by2%", wrm.By2)
                        .Replace("%by3%", wrm.By3)
                        .Replace("%by4%", wrm.By4)
                        .Replace("%by5%", wrm.By5)
                        .Replace("%by6%", wrm.By6)
                        .Replace("%by7%", wrm.By7)
                        .Replace("%by8%", wrm.By8)
                        .Replace("%by9%", wrm.By9)
                        .Replace("%by10%", wrm.By10);

        speaker.SpeakAsync(str);
      }
      catch { }
    }

  }
}
